import request from '../utils/request';
import storage from '../utils/storage';

export function query() {
    return request('/api/users');
}
// 登录
export async function login(params) {
    const {data} = await request('/api/login', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(params)
    });
    if(data.status===200&&data.msg==='success'){
        const token=data.data.token;
        delete data.data.token;
        storage.set('userInfo',data.data);
        storage.set('token',token);
    }
    return data;
}
// 退出登录
export function logout(){
    storage.remove('userInfo');
    storage.remove('token');
    return true;
}
// 检测登录状态
export function checkLogin(){
    const token=storage.get('token');
    return token!==null?true:false;
}